package com.fingard.dsp.bank.directbank.jrtt02;

import com.alibaba.fastjson.JSON;
import com.bytedance.ea.rulevalidator.api.PaymentInfoVerifyService;
import com.bytedance.ea.rulevalidator.api.PaymentRuleBasicService;
import com.bytedance.ea.rulevalidator.api.PaymentRuleDetailService;
import com.bytedance.ea.rulevalidator.api.RuleVersionService;
import com.bytedance.ea.rulevalidator.api.dto.*;
import com.fingard.FGBiz;
import com.fingard.dsp.bank.directbank.bankInterface.IForeignCurrCheck;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck.ReqCJFrgCurrCheck;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck.RetAtsCJFrgCurrCheck;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck.detail.CJFrgCurrCheckDetail;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglecheck.detail.RetAtsCJFrgCurrCheckDetail;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.ReqCJFrgCurrGetVal;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.RetAtsCJFrgCurrGetVal;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.detail.FrgCurrSingleBasic;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.detail.FrgCurrSingleField;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.detail.FrgCurrSingleTemplate;
import com.fingard.dsp.bank.reqrespobj.frgcurrsinglegetval.detail.RetAtsCJFrgCurrGetValDetail;
import com.fingard.io.FileHelper;
import com.fingard.text.StringHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 财经-海外接口
 */
public class JRTT02ForeignCurrCheck extends JRTT02Base implements IForeignCurrCheck {

    /**
     * 付款信息校验
     *
     * @param reqCheckSingleBat
     * @return
     * @throws Exception
     */
    @Override
    public RetAtsCJFrgCurrCheck checkFrgCurrPayValue(ReqCJFrgCurrCheck reqCheckSingleBat) throws Exception {
        RetAtsCJFrgCurrCheck retAts = new RetAtsCJFrgCurrCheck(reqCheckSingleBat.reqHeader);
        try {
            //获取请求字段信息集合 list<PaymentInfo>
            List<PaymentInfo> paymentInfoList = new ArrayList<PaymentInfo>();
            int count = 0;//统计数量
            while (reqCheckSingleBat.readRecord()) {
                CJFrgCurrCheckDetail tmpDetail = reqCheckSingleBat.readedDetail;
                PaymentInfo paymentInfo = new PaymentInfo();
                paymentInfo.setEndToEndId(tmpDetail.askNumber);//批内流水
                if (StringHelper.hasAnyChar(tmpDetail.name) && StringHelper.hasAnyChar(tmpDetail.value)) {
                    //获取字段信息集合
                    List<FieldValue> filedValueList = xmlWriterBodyByRpc(tmpDetail.name, tmpDetail.value, tmpDetail.fieldNum);
                    //添加模板信息
                    if (filedValueList != null && filedValueList.size() > 0) {
                        FieldValue filedValue = new FieldValue();
                        filedValue.setFieldName("TemplateName");
                        filedValue.setValue(tmpDetail.templateName);
                        filedValueList.add(filedValue);
                    } else {
                        retAts.batRespCode = "-1";
                        retAts.batRespInfo = "付款信息预检异常";
                        retAts.writeAfterDetail();
                        return retAts;
                    }
                    paymentInfo.setPaymentFields(filedValueList);
                } else {
                    retAts.batRespCode = "-1";
                    retAts.batRespInfo = "请求name或value不能为空";
                    retAts.writeAfterDetail();
                    return retAts;
                }
                paymentInfoList.add(paymentInfo);
                count++;
            }
            if (count != Integer.parseInt(reqCheckSingleBat.recordNum)) {
                retAts.batRespCode = "-1";
                retAts.batRespInfo = "DetailRecord总数据与RecordNum不一致";
                WriteBankLogLn("DetailRecord总数据与RecordNum不一致");
                retAts.writeAfterDetail();
                return retAts;
            }
            //Base
            RuleBaseReq ruleBaseReq = writeRuleBaseReq(new JRTT02Header());
            //PaymentInfoVerifyReq
            PaymentInfoVerifyReq paymentInfoVerifyReq = new PaymentInfoVerifyReq();
            paymentInfoVerifyReq.setBaseReq(ruleBaseReq);
            paymentInfoVerifyReq.setForPayment("");//false
            paymentInfoVerifyReq.setPaymentInfos(paymentInfoList);//字段信息集合
            //发现
            DubboBeanFactory beanFactory = new DubboBeanFactory(bankFront, getBankConfig());
            PaymentInfoVerifyService.Iface verify = beanFactory.getVerifyService();
            //调用
            WriteBankLogStep2("PaymentInfoVerifyReq：" + JSON.toJSONString(paymentInfoVerifyReq));
            PaymentInfoVerifyRsp paymentInfoVerifyRsp = verify.execute(paymentInfoVerifyReq);
            WriteBankLogStep3("PaymentInfoVerifyRsp：" + paymentInfoVerifyRsp);
            //解析
            if (paymentInfoVerifyRsp.getBaseRsp() != null) {
                String returnCode = paymentInfoVerifyRsp.getBaseRsp().getResponseStatus();//返回码
                String returnMsg = paymentInfoVerifyRsp.getBaseRsp().getAddtlInf();//返回信息
                retAts.batRespCode = "0";
                retAts.batRespInfo = returnMsg;
                retAts.reqBatchNO = reqCheckSingleBat.reqBatchNO;
                retAts.batTransState = returnCode;
                retAts.batPayInfoCode = retAts.batTransState;
                List<PaymentInfoVerifyResult> paymentInfoVerifyResultList = paymentInfoVerifyRsp.getPaymentInfos();
                if (paymentInfoVerifyResultList != null && paymentInfoVerifyResultList.size() > 0) {
                    for (PaymentInfoVerifyResult result : paymentInfoVerifyResultList) {
                        RetAtsCJFrgCurrCheckDetail retAtsCheckDetail = new RetAtsCJFrgCurrCheckDetail();
                        String transState = result.getStatus();
                        retAtsCheckDetail.reqSeqID = result.getEndToEndId();
                        retAtsCheckDetail.respCode = "0";
                        retAtsCheckDetail.transState = transState;
                        retAtsCheckDetail.payInfoCode = retAtsCheckDetail.transState;
                        retAtsCheckDetail.respInfo = result.getMessage();
                        if ("ERRO".equals(transState)) {
                            if (result.getPaymentFields() != null) {
                                StringBuilder sbd = new StringBuilder();
                                if (result.getMessage() != null) {
                                    sbd.append(result.getMessage()).append(" ");
                                }
                                for (FieldVerifyMessage message : result.getPaymentFields()) {
                                    sbd.append(message.getMessage()).append(",");
                                }
                                retAtsCheckDetail.respInfo = sbd.deleteCharAt(sbd.length() - 1).toString();
                            }
                        }
                        retAts.writeRetDetail(retAtsCheckDetail);
                    }
                }
            } else {
                retAts.batRespCode = "-1";
                retAts.batRespInfo = "返回BaseRsp为空";
            }
        } catch (Exception e) {
            e.printStackTrace();
            retAts.batRespCode = "-1";
            retAts.batRespInfo = e.getMessage();
            WriteBankLogLn("付款信息校验异常：" + e);
        }
        retAts.writeAfterDetail();
        return retAts;
    }

    /**
     * 获取付款元素
     *
     * @param reqFrgCurrSingle
     * @return
     * @throws Exception
     */
    @Override
    public RetAtsCJFrgCurrGetVal getFrgCurrPayValue(ReqCJFrgCurrGetVal reqFrgCurrSingle) throws Exception {
        RetAtsCJFrgCurrGetVal retAts = new RetAtsCJFrgCurrGetVal(reqFrgCurrSingle.reqHeader);
        retAts.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";
        String versionFilePath = "";//存放元素数据
        String ruleVersion = "";//版本号
        try {
            WriteBankLogLn("开始获取付款元素，请求获取版本号为【" + reqFrgCurrSingle.version + "】");

            List<FrgCurrSingleBasic> currSingleOneList = new ArrayList<FrgCurrSingleBasic>();
            List<FrgCurrSingleBasic> currSingleList = new ArrayList<FrgCurrSingleBasic>();//存放响应的关键词，便于接口二请求
            //版本号数据存放目录
            versionFilePath = FGBiz.dspCenter.dspSet.dataDirPath + File.separator + "dataFile" + File.separator + bankFront.code + File.separator + "versionFile";
            if (!FileHelper.existFile(versionFilePath)) {
                FileHelper.mkdir(versionFilePath);
            }
            FrgCurrSingleBasic currSingleOne = null;
            //======接口一 payment_rule======
            RuleBaseReq ruleBaseReq = writeRuleBaseReq(new JRTT02Header());
            DubboBeanFactory beanFactory = new DubboBeanFactory(bankFront, getBankConfig());
            RuleVersionService.Iface ruleVersionService = beanFactory.getRuleVersionService();
            //调用
            WriteBankLogStep2("RuleBaseReq：" + ruleBaseReq);
            RuleVersionRsp ruleVersionRsp = ruleVersionService.execute(ruleBaseReq);
            WriteBankLogStep3("RuleVersionRsp：" + ruleVersionRsp.toString());
            //处理响应报文
            if (ruleVersionRsp.getBaseRsp() != null) {
                if ("ACCP".equals(ruleVersionRsp.getBaseRsp().getResponseStatus())) {
                    ruleVersion = ruleVersionRsp.getRuleVersion();//版本号
                    WriteBankLogLn("银行响应版本号为【" + ruleVersion + "】");
                    if (StringHelper.isNullOrEmpty(ruleVersion)) {
                        tmpRespCode = "-1";
                        tmpRespInfo = "响应版本号为空";
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = ruleVersionRsp.getBaseRsp().getAddtlInf();
                }
            } else {
                tmpRespCode = "-1";
                tmpRespInfo = "BaseRsp响应为空";
            }
            if (!"-1".equals(tmpRespCode)) {
                WriteBankLogLn("查询的版本号为【" + ruleVersion + "】");
                if (StringHelper.hasAnyChar(reqFrgCurrSingle.version) && Long.parseLong(ruleVersion) <= Long.parseLong(reqFrgCurrSingle.version)) {
                    String versionFilePath2 = versionFilePath + File.separator + reqFrgCurrSingle.version + ".txt";
                    if (FileHelper.existFile(versionFilePath2)) {
                        WriteBankLogLn("此版本号在本地存在，开始获取版本号【" + reqFrgCurrSingle.version + "】，目录【" + versionFilePath2 + "】存放的数据");
                        //获取此版本存放的数据
                        String rspXml = FileHelper.readFileText(versionFilePath2, getCharset());
                        if (StringHelper.hasAnyChar(rspXml) && rspXml.contains(reqFrgCurrSingle.version)) {
                            //相同版本号，直接返回ats
                            retAts = new RetAtsCJFrgCurrGetVal(reqFrgCurrSingle.reqHeader);
                            retAts.writeRetXml(rspXml);
                            return retAts;
                        }
                    } else {
                        WriteBankLogLn("此版本号在本地不存在，开始向银行发起接口请求");
                    }
                }
            }
            if (!"-1".equals(tmpRespCode)) {
                //======接口二 payment_basic======
                //调用服务
                PaymentRuleBasicService.Iface basicClient = beanFactory.getBasicService();
                WriteBankLogStep2("RuleBaseReq：" + ruleBaseReq);
                PaymentRuleBasicRsp paymentRuleBasicRsp = basicClient.execute(ruleBaseReq);
                WriteBankLogStep3("PaymentRuleBasicRsp：" + paymentRuleBasicRsp.toString());
                //处理响应报文
                if (paymentRuleBasicRsp.getBaseRsp() != null) {
                    if ("ACCP".equals(paymentRuleBasicRsp.getBaseRsp().getResponseStatus())) {
                        List<BankChannel> bankChannelList = paymentRuleBasicRsp.getBankChannels();
                        if (bankChannelList != null && bankChannelList.size() > 0) {
                            for (BankChannel bankChannel : bankChannelList) {
                                currSingleOne = new FrgCurrSingleBasic();
                                currSingleOne.bankType = bankChannel.getBankType();
                                List<PayBankCountryDto> payBankCountryList = bankChannel.getPayBankCountries();
                                if (payBankCountryList != null && payBankCountryList.size() > 0) {
                                    for (PayBankCountryDto payBankCountry : payBankCountryList) {
                                        currSingleOne = new FrgCurrSingleBasic();
                                        currSingleOne.bankType = bankChannel.getBankType();
                                        currSingleOne.payBankCountryCode = payBankCountry.getPaybankCountryCode();
                                        List<PayMethodDto> payMethodList = payBankCountry.getPayMethod();
                                        if (payMethodList != null && payMethodList.size() > 0) {
                                            for (PayMethodDto payMethod : payMethodList) {
                                                currSingleOne = new FrgCurrSingleBasic();
                                                currSingleOne.bankType = bankChannel.getBankType();
                                                currSingleOne.payBankCountryCode = payBankCountry.getPaybankCountryCode();
                                                currSingleOne.methodName = payMethod.getMethodName();
                                                List<CountryCurrencyGroupDto> countryCurrencyGroupList = payMethod.getCountryCurrencyGroup();
                                                if (countryCurrencyGroupList != null && countryCurrencyGroupList.size() > 0) {
                                                    for (CountryCurrencyGroupDto countryCurrencyGroup : countryCurrencyGroupList) {
                                                        currSingleOne = new FrgCurrSingleBasic();
                                                        currSingleOne.bankType = bankChannel.getBankType();
                                                        currSingleOne.payBankCountryCode = payBankCountry.getPaybankCountryCode();
                                                        currSingleOne.methodName = payMethod.getMethodName();
                                                        List<String> payCurrencyList = countryCurrencyGroup.getPayCurrencies();
                                                        List<String> beneBankCountryList = countryCurrencyGroup.getBeneBankCountrys();
                                                        //如果币种返回空，说明支持全币种
                                                        if (payCurrencyList == null || payCurrencyList.size() == 0) {
                                                            payCurrencyList.add("*");
                                                        }
                                                        //如果国家返回空，说明支持全国家
                                                        if (beneBankCountryList == null || beneBankCountryList.size() == 0) {
                                                            beneBankCountryList.add("*");
                                                        }
                                                        for (String payCurrency : payCurrencyList) {
                                                            for (String beneBankCountry : beneBankCountryList) {
                                                                currSingleOne = new FrgCurrSingleBasic();
                                                                currSingleOne.bankType = bankChannel.getBankType();
                                                                currSingleOne.payBankCountryCode = payBankCountry.getPaybankCountryCode();
                                                                currSingleOne.methodName = payMethod.getMethodName();
                                                                currSingleOne.payCurrency = payCurrency;
                                                                currSingleOne.beneBankCountry = beneBankCountry;
                                                                currSingleList.add(currSingleOne);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = paymentRuleBasicRsp.getBaseRsp().getAddtlInf();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = "BaseRsp响应为空";
                }
            }
            //======接口三 payment_detail======
            if (!"-1".equals(tmpRespCode) && currSingleList != null && currSingleList.size() > 0) {
                //开始获取详细付款信息
                for (FrgCurrSingleBasic frgCurrSingleBasic : currSingleList) {
                    WriteBankLogLn("请求参数：" + frgCurrSingleBasic.bankType + "|" + frgCurrSingleBasic.payBankCountryCode + "|" + frgCurrSingleBasic.methodName + "|"
                            + frgCurrSingleBasic.payCurrency + "|" + frgCurrSingleBasic.beneBankCountry + "|");

                    PaymentRuleDetailReq paymentRuleDetailReq = new PaymentRuleDetailReq();
                    paymentRuleDetailReq.setBankType(frgCurrSingleBasic.bankType);
                    paymentRuleDetailReq.setPayBankCountryCode(frgCurrSingleBasic.payBankCountryCode);
                    paymentRuleDetailReq.setMethodName(frgCurrSingleBasic.methodName);
                    paymentRuleDetailReq.setPayCurrency(frgCurrSingleBasic.payCurrency);
                    paymentRuleDetailReq.setBeneBankCountry(frgCurrSingleBasic.beneBankCountry);
                    paymentRuleDetailReq.setBaseReq(ruleBaseReq);
                    //调用服务
                    WriteBankLogStep2("PaymentRuleDetailReq：" + paymentRuleDetailReq);
                    PaymentRuleDetailService.Iface detailClient = beanFactory.getDetailService();
                    PaymentRuleDetailRsp paymentRuleDetailRsp = detailClient.execute(paymentRuleDetailReq);
                    //处理响应报文
                    String[] respArr = new String[]{tmpRespCode, tmpRespInfo};
                    dealWithXmlByRpc(paymentRuleDetailRsp, paymentRuleDetailReq, retAts, respArr, ruleVersion);
                    tmpRespCode = respArr[0];
                    tmpRespInfo = respArr[1];
                }
            }
        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            ex.printStackTrace();
            WriteBankLogLn("查询付款可用元素异常:" + ex);
        }
        if ("-1".equals(tmpRespCode)) {
            retAts = new RetAtsCJFrgCurrGetVal(reqFrgCurrSingle.reqHeader);
            retAts.writeStart();//写返回ATS的统一头部信息
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            retAts.writeRespInfo("交易为空");
            retAts.writeRespCode("0");
        }
        retAts.writeEnd();
        if (!"-1".equals(tmpRespCode) && retAts.getWrittenRdCount() > 0 && StringHelper.hasAnyChar(versionFilePath)) {
            String saveVsionFilePath = versionFilePath + File.separator + ruleVersion + ".txt";
            if (!FileHelper.existFile(saveVsionFilePath)) {
                FileHelper.writeFile(saveVsionFilePath, retAts.getRetAtsString(), getCharset());
                WriteBankLogLn2("写入文件：" + saveVsionFilePath + ",文件内容 \r\n");
            } else {
                WriteBankLogLn2("文件已存在：" + saveVsionFilePath);
            }
        }
        return retAts;
    }

    /**
     * 处理银行响应的报文--获取元素
     *
     * @param paymentRuleDetailRsp 响应报文
     * @param retAts               响应到ats
     * @param respArr              状态信息
     * @throws Exception
     */
    private void dealWithXmlByRpc(PaymentRuleDetailRsp paymentRuleDetailRsp, PaymentRuleDetailReq paymentRuleDetailReq,
                                  RetAtsCJFrgCurrGetVal retAts, String[] respArr, String version) throws Exception {
        WriteBankLogStep3("PaymentRuleDetailRsp：" + paymentRuleDetailRsp);
        if (paymentRuleDetailRsp.getBaseRsp() != null) {
            if ("ACCP".equals(paymentRuleDetailRsp.getBaseRsp().getResponseStatus())) {
                RetAtsCJFrgCurrGetValDetail detail = new RetAtsCJFrgCurrGetValDetail();
                detail.bankType = paymentRuleDetailReq.getBankType();//银行类型
                detail.payBankCountryCode = paymentRuleDetailReq.getPayBankCountryCode();//ISO3166 2位国家代码
                detail.methodName = paymentRuleDetailReq.getMethodName();//付款方式
                detail.payCurrency = paymentRuleDetailReq.getPayCurrency();//ISO4217 3位币种代码
                detail.beneBankCountry = paymentRuleDetailReq.getBeneBankCountry();//ISO3166 2位国家代码
                detail.version = version;
                List<FrgCurrSingleTemplate> frgCurrSingleTemplateList = new ArrayList<FrgCurrSingleTemplate>();
                List<PaymentTemplateDto> paymentTemplateDtoList = paymentRuleDetailRsp.getTemplates();//模板循环体
                if (paymentTemplateDtoList != null && paymentTemplateDtoList.size() > 0) {
                    for (PaymentTemplateDto paymentTemplateDto : paymentTemplateDtoList) {
                        FrgCurrSingleTemplate template = new FrgCurrSingleTemplate();
                        template.templateName = paymentTemplateDto.getTemplateName();
                        template.templateDescZh = paymentTemplateDto.getTemplateDescZh();
                        template.templateDescEn = paymentTemplateDto.getTemplateDescEn();
                        List<FieldRule> fieldRuleList = paymentTemplateDto.getRules();
                        List<FrgCurrSingleField> frgCurrSingleFieldList = new ArrayList<FrgCurrSingleField>();
                        if (fieldRuleList != null && fieldRuleList.size() > 0) {
                            for (FieldRule fieldRule : fieldRuleList) {
                                FrgCurrSingleField frgCurrSingleField = new FrgCurrSingleField();
                                frgCurrSingleField.name = fieldRule.getFieldName();//字段名
                                frgCurrSingleField.reqiured = typeConversion(fieldRule.getReqiured());//mandatory-必输，supress-不输入，optional-选输
                                //枚举取值
                                String enums = fieldRule.getEnums();//枚举值
                                if (enums == null) {
                                    enums = "";
                                }
                                if (enums.contains(flag)) {
                                    List<PurposeCode> purposeCodeList = new ArrayList<PurposeCode>();
                                    if (enums.replace(flag, "").equals("InboundPurpCode")) {
                                        purposeCodeList = paymentTemplateDto.getInboundPurposes();
                                    } else if (enums.replace(flag, "").equals("OutboundPurpCode")) {
                                        purposeCodeList = paymentTemplateDto.getOutboundPurposes();
                                    }
                                    if (purposeCodeList != null && purposeCodeList.size() > 0) {
                                        StringBuilder sb = new StringBuilder();
                                        for (PurposeCode purposeCode : purposeCodeList) {
                                            if (StringHelper.hasAnyChar(purposeCode.getCode())) {
                                                sb.append(purposeCode.getCode());
                                            }
                                            if (StringHelper.hasAnyChar(purposeCode.getDesc())) {
                                                sb.append("-||-").append(purposeCode.getDesc()).append("@@");
                                            }
                                            if ("true".equals(purposeCode.getDefaultFlag())) {
                                                frgCurrSingleField.Default = purposeCode.getDefaultFlag();
                                            }
                                        }
                                        frgCurrSingleField.checkRule = "5";
                                        if (sb.length() > 2) {
                                            frgCurrSingleField.enums = sb.deleteCharAt(sb.length() - 2).toString();//以,分割多个可能的枚举值
                                        }
                                    }
                                } else {
                                    frgCurrSingleField.enums = enums.replaceAll(",", "@@");//以,分割多个可能的枚举值
                                }
                                //checkRule、type处理方式
                                String checkRule = "";
                                String type = "0";
                                String rule = "";
                                if (fieldRule.getCheckRules() != null && fieldRule.getCheckRules().size() > 0) {
                                    //取第一行的rule
                                    CheckRule ruleList = fieldRule.getCheckRules().get(0);
                                    rule = ruleList.getValue();
                                    String msgEn = ruleList.getMessageEn();
                                    String msgZh = ruleList.getMessageZh();
                                    if (StringHelper.hasAnyChar(msgEn)) {
                                        if (msgEn.contains("date")) {
                                            type = "2";
                                            checkRule = "10";
                                        } else if (msgEn.contains("amount")) {
                                            type = "1";
                                            checkRule = "";
                                        } else {
                                            type = "0";
                                            checkRule = getMaxLength(msgZh);
                                        }
                                    } else {
                                        type = "0";
                                        checkRule = "";
                                    }
                                } else {
                                    type = "0";
                                    checkRule = "";
                                }

                                frgCurrSingleField.checkRule = checkRule;//
                                frgCurrSingleField.type = type;//字段类型
                                frgCurrSingleField.regex = StringHelper.hasAnyChar(rule) ? "<![CDATA[" + rule + "]]" : rule;//正则表达式
                                //charSetCheck处理方式
                                String charSetCheck = fieldRule.getCharSetCheck();
                                if ("true".equals(charSetCheck)) {
                                    frgCurrSingleField.charSetCheck = "<![CDATA[" + paymentTemplateDto.getCharSet() + "]]>";
                                } else {
                                    frgCurrSingleField.charSetCheck = "";//字符集
                                }
                                frgCurrSingleFieldList.add(frgCurrSingleField);
                            }
                        }
                        template.field = frgCurrSingleFieldList;
                        frgCurrSingleTemplateList.add(template);
                    }
                }
                detail.template = frgCurrSingleTemplateList;
                retAts.writeRetDetail(detail);
            } else if ("ERRO".equals(paymentRuleDetailRsp.getBaseRsp().getResponseStatus())) {
                RetAtsCJFrgCurrGetValDetail detail = new RetAtsCJFrgCurrGetValDetail();
                detail.bankType = paymentRuleDetailReq.getBankType();//银行类型
                detail.payBankCountryCode = paymentRuleDetailReq.getPayBankCountryCode();//ISO3166 2位国家代码
                detail.methodName = paymentRuleDetailReq.getMethodName();//付款方式
                detail.payCurrency = paymentRuleDetailReq.getPayCurrency();//ISO4217 3位币种代码
                detail.beneBankCountry = paymentRuleDetailReq.getBeneBankCountry();//ISO3166 2位国家代码
                detail.version = version;
                detail.template = null;
                retAts.writeRetDetail(detail);
            } else {
                respArr[0] = "-1";
                respArr[1] = paymentRuleDetailRsp.getBaseRsp().getAddtlInf();
            }
        } else {
            respArr[0] = "-1";
            respArr[1] = "BaseRsp为空";
        }
    }
}
